package com.ttg.web.dao.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ttg.common.entities.BaseResult;
import com.ttg.model.dto.open.BindPeopleVipDto;
import com.ttg.model.mapper.VipBindPeopleMapper;
import com.ttg.model.pojo.VipBindPeople;
import com.ttg.model.vo.open.BindPeopleVipVo;
import com.ttg.web.dao.VipBindPeopleDao;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class VipBindPeopleDaoImpl extends ServiceImpl<VipBindPeopleMapper, VipBindPeople> implements VipBindPeopleDao {
    @Override
    public boolean deleteBytPepId(Integer pepId) {
        LambdaUpdateWrapper<VipBindPeople> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(VipBindPeople::getPepId,pepId);
        return remove(wrapper);
    }

    @Override
    public int addVipBindPeople(List<VipBindPeople> vipBindPeopleList) {
        return baseMapper.addVipBindPeople(vipBindPeopleList);
    }

    @Override
    public List<Long> selectByPepId(Long pepId) {
        // 使用LambdaQueryWrapper进行查询
        LambdaQueryWrapper<VipBindPeople> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(VipBindPeople::getVipId);
        queryWrapper.eq(VipBindPeople::getPepId, pepId);
        List<VipBindPeople> vipBindPeopleList = baseMapper.selectList(queryWrapper);

        // 提取vipId并装入List中
        return vipBindPeopleList.stream()
                .map(VipBindPeople::getVipId)
                .collect(Collectors.toList());
    }

    @Override
    public List<BindPeopleVipVo> bindPeopleVip(BindPeopleVipDto dto) {
        return baseMapper.bindPeopleVip(dto);
    }
}
